package com.mlh.controller;

import com.mlh.dto.AddCommentDto;
import com.mlh.entity.Comment;
import com.mlh.service.CommentService;
import com.mlh.util.BeanCopyUtil;
import com.mlh.util.ResponseResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 缪林辉
 * @date 2024/3/15 20:56
 * @DESCRIPTION
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论",description = "评论相关接口")
public class CommentController {
    @Autowired
    private CommentService commentService;

    //查询文章评论列表
    @GetMapping("/commentList")
    public ResponseResult commentList(Long articleId,Integer pageNum,Integer pageSize){
        return commentService.commentList(articleId,pageNum,pageSize);
    }
    //获取友联评论列表
    @GetMapping("/linkCommentList")
    public ResponseResult linkCommentList(Integer pageNum,Integer pageSize){
        return commentService.linkCommentList(pageNum,pageSize);
    }

    //发表评论
    @PostMapping
    public ResponseResult addComment(@RequestBody AddCommentDto addCommentDto){
        //AddCommentDto属性值赋给Comment对象，AddCommentDto起到个中转作用
        Comment comment = BeanCopyUtil.copyBean(addCommentDto, Comment.class);
        return commentService.addCommetn(comment);
    }
}
